using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;

namespace TimeWar
{
    public class ChaseCamera : Camera
    {

        protected Vector3 prevObjPosition;

        protected Vector3 desiredPositionOffset = new Vector3(0, 10f, -100f);

        public Vector3 DesiredPositionOffset
        {
            get
            {
                return desiredPositionOffset;
            }
            set
            {
                desiredPositionOffset = value;
            }
        }

        protected Vector3 up;

        public Vector3 Up
        {
            get
            {
                return up;
            }
            set
            {
                up = value;
            }
        }

        /// <summary>
        /// Distance to the near clipping plane.
        /// </summary>
        //public float NearPlaneDistance
        //{
        //    get { return nearPlaneDistance; }
        //    set { nearPlaneDistance = value; }
        //}
        //private float nearPlaneDistance = 1.0f;

        /// <summary>
        /// Distance to the far clipping plane.
        /// </summary>
        //public float FarPlaneDistance
        //{
        //    get { return farPlaneDistance; }
        //    set { farPlaneDistance = value; }
        //}
        //private float farPlaneDistance = 10000.0f;

        public ChaseCamera() : base()
        {
        }


        public override void Update(Vector3 objPosition, Quaternion objRotation)
        {
            position = Vector3.Add(desiredPositionOffset, objPosition);
            position = Vector3.Transform(position, Matrix.CreateFromQuaternion(objRotation));

            up = Vector3.Up;
            up = Vector3.Transform(up, Matrix.CreateFromQuaternion(objRotation));
            up.Normalize();

            view = Matrix.CreateLookAt(position, objPosition, up);
            projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4, aspectRatio, nearClip, farClip);

            if (prevObjPosition == objPosition)
            {
                //ship hasn't moved.
                //chasePosition.X++;
            }
            else
            {
                prevObjPosition = objPosition;
            }

            updateFrustrum();


        }

    }
}